package com.wedata.海康云;

import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

public class 门禁权限控制 extends BaseService{


    public static void main(String[] args) {
        //searchAuthPage();
        //searchRulePage();
        //searchRuleInfo("8dcc7562367f614f3cc8bb27174c28d5");
        //searchRuleInfo("8dcc7562367f614f3cc8bb27174c28d5");
        //searchTemplatePage();
        //searchTemplateInfo(1);
        //addRule();
        //updateRule(); -- 规则更新会引起权限刷新--慎重
        //searchRuleInfo("8dcc7562367f614f3cc8bb27174c28d5");
        refresh();
    }

    public static String searchAuthPage(){
        JSONObject param = new JSONObject();
        param.set("pageNo",1);
        param.set("pageSize",10);
        param.set("deviceSerials",new String[]{"AE6891584"});
        JSONObject header = new JSONObject("{\"access_token\":\""+getToken()+"\"}");
        JSONObject jsonObject = HttpUtils.sendPost("https://open.hikyun.com/artemis/api/eits/acpmcs/v1/auth/detail/page",header,param);

        System.out.println(jsonObject);
        return jsonObject.toString();
    }

    /**
     * 分页查询通行规则信息
     * @return
     */
    public static String searchRulePage(){
        JSONObject param = new JSONObject();
        param.set("pageNo",1);
        param.set("pageSize",100);
        JSONObject header = new JSONObject("{\"access_token\":\""+getToken()+"\"}");
        JSONObject jsonObject = HttpUtils.sendPost("https://open.hikyun.com/artemis/api/eits/acpmcs/v1/auth/rule/page",header,param);

        System.out.println(jsonObject);
        return jsonObject.toString();
    }
    /**
     * 查询通行规则详情信息
     * @return
     */
    public static String searchRuleInfo(String ruleId){
        JSONObject param = new JSONObject();
        param.set("ruleIds", new String[]{ruleId});
        JSONObject header = new JSONObject("{\"access_token\":\""+getToken()+"\"}");
        JSONObject jsonObject = HttpUtils.sendPost("https://open.hikyun.com/artemis/api/eits/acpmcs/v1/auth/rule/search",header,param);

        System.out.println(jsonObject);
        return jsonObject.toString();
    }

    /**
     * 新增规则
     * @return
     */
    public static String addRule(){
        //{"msg":null,"code":"200","data":{"ruleId":"8dcc7562367f614f3cc8bb27174c28d5"}}
        JSONObject param = new JSONObject();
        param.set("projectId",projectId);
        param.set("productCode",productCode);
        param.set("ruleName", "约课调研组");

        param.set("deviceSerials", new String[]{"AE6891584"});//new String[]{"AE6891584","J96243743"}

        param.set("orgIds", new String[]{"2164837673736880","361013479217840"});
        param.set("personGroupIds", new String[]{"2165211671547568"});

        param.set("templateIndex", 6);
        JSONObject header = new JSONObject("{\"access_token\":\""+getToken()+"\"}");
        JSONObject jsonObject = HttpUtils.sendPost("https://open.hikyun.com/artemis/api/eits/acpmcs/v1/auth/rule/add",header,param);

        System.out.println(jsonObject);
        return jsonObject.toString();
    }

    /**
     * 更新规则
     * @return
     */
    public static String updateRule(){
        JSONObject param = new JSONObject();
        param.set("projectId",projectId);
        param.set("productCode",productCode);

        param.set("ruleId", "8dcc7562367f614f3cc8bb27174c28d5");
        param.set("ruleName", "总部负一楼");

        param.set("deviceSerials", new String[]{"AE6891584"});//new String[]{"AE6891584","J96243743"}

        //param.set("orgIds", new String[]{"2164837673736880","361013479217840"});

        param.set("personGroupIds", new String[]{"2165211671547568"});//563131970044840

        param.set("templateIndex", 1);
        JSONObject header = new JSONObject("{\"access_token\":\""+getToken()+"\"}");
        JSONObject jsonObject = HttpUtils.sendPost("https://open.hikyun.com/artemis/api/eits/acpmcs/v1/auth/rule/update",header,param);

        System.out.println(jsonObject);
        return jsonObject.toString();
    }

    /**
     * 查询计划模版 -- 计划模版--运营后台加--接口不管
     * @return
     */
    private String searchTemplatePage(){
        JSONObject param = new JSONObject();
        param.set("pageNo",1);
        param.set("pageSize",10);
        JSONObject header = new JSONObject("{\"access_token\":\""+getToken()+"\"}");
        JSONObject jsonObject = HttpUtils.sendPost("https://open.hikyun.com/artemis/api/eits/acpmcs/v1/template/name/search",header,param);
        //{"msg":null,"code":"200","data":{"templateList":[{"defaultStatus":1,"templateIndex":9,"templateName":"测试模板"},{"defaultStatus":1,"templateIndex":8,"templateName":"7_50-22_40"},{"defaultStatus":1,"templateIndex":7,"templateName":"7_30-22_40"},{"defaultStatus":1,"templateIndex":6,"templateName":"7_20-22_40"},{"defaultStatus":1,"templateIndex":5,"templateName":"门店时段-七点"},{"defaultStatus":1,"templateIndex":4,"templateName":"超级权限"},{"defaultStatus":1,"templateIndex":3,"templateName":"疫情期间"},{"defaultStatus":1,"templateIndex":2,"templateName":"门店时段-八点"},{"defaultStatus":1,"templateIndex":1,"templateName":"默认计划模板"}]}}
        System.out.println(jsonObject);
        return jsonObject.toString();
    }
    /**
     * 查询计划模版-- 计划模版--运营后台加--接口不管
     * @return
     */
    private String searchTemplateInfo(Integer templateIndex){
        JSONObject param = new JSONObject();
        param.set("templateIndexs", new Integer[]{templateIndex});
        JSONObject header = new JSONObject("{\"access_token\":\""+getToken()+"\"}");
        JSONObject jsonObject = HttpUtils.sendPost("https://open.hikyun.com/artemis/api/eits/acpmcs/v1/template/detail/search",header,param);

        System.out.println(jsonObject);
        return jsonObject.toString();
    }

    /**
     * 重新下发人员信息
     * @return
     */
    public static String refresh(){
        JSONObject param = new JSONObject();
        param.set("projectId",projectId);
        param.set("productCode",productCode);

        JSONObject personDevice = new JSONObject();
        personDevice.set("deviceSerial","AE6891584");
        personDevice.set("personId","792996529064");
        param.set("personDeviceList", new JSONObject[]{personDevice});

        JSONObject header = new JSONObject("{\"access_token\":\""+getToken()+"\"}");
        JSONObject jsonObject = HttpUtils.sendPost("https://open.hikyun.com/artemis/api/eits/acpmcs/v1/auth/download/device/person/refresh",header,param);

        //{"msg":null,"code":"200","data":null}
        System.out.println(jsonObject);
        return jsonObject.toString();
    }


}
